<?php
/**
 * Manageaccount_Data_Updateuserprivatedata
 * update user private data
 * @author Adrian Stolarski
 */
class Manageaccount_Data_Updateuserprivatedata implements Manageaccount_Data_Mainable, 
        Manageaccount_Data_Preparable {
    
    /**
     *
     * @var type $database
     * database handler
     */
    public $database;
    /**
     *
     * @var type $database_query
     */
    public $database_query;
    /**
     *
     * @var type $redirect_action
     */
    public $redirect_action;
    
    /**
     * constructor()
     */
    public function __construct() {
        $this->database = new Core_Driver_MysqlImproved;
    }
    
    /**
     * main()
     * update main user data
     * 
     * @param array $variables
     */
    public function main(array $variables = null) {
        $this->database->connect();
        foreach($variables as $key => $value){
            $variables[$key] = $this->database->escape($value);
        }
        //var_dump($variables);
        //die();
        $this->prepare_query($variables);
        $this->database->prepare($this->database_query);
        $this->database->query();
        $this->database->dataOperations();
        $this->redirect_action = new Manageaccount_Data_Redirectmanageaccount;
        $this->redirect_action->main($variables);
    }
    
    /**
     * prapare_query()
     * prepare database query
     * 
     * @param array $variables
     */
    public function prepare_query(array $variables = null) {
        //var_dump($variables);
        //die();
        $this->database_query = "UPDATE "
                . "user_private_data"
                . " SET "
                . "user_tax_identification_number='"
                .$variables['user_tax_identification_number'].
                "', "
                . "user_street='"
                .$variables['user_street'].
                "', "
                . "user_local_number='"
                .$variables['user_local_number'].
                "', "
                . "user_postal_code='"
                .$variables['user_postal_code'].
                "', "
                . "user_city='"
                .$variables['user_city'].
                "', "
                . "user_telephone_number='"
                .$variables['user_telephone_number']."'"
                . " WHERE "
                . "private_user_id="
                .$variables['user_id'].
                ";";
        //echo $this->database_query;
        //die();
    }

}

